package com.kakarote.examine.controller;

import com.kakarote.core.common.Result;
import com.kakarote.core.entity.BasePage;
import com.kakarote.core.feign.oa.entity.ExamineVO;
import com.kakarote.core.utils.ExcelParseUtil;
import com.kakarote.core.utils.UserUtil;
import com.kakarote.examine.entity.BO.ExamineBO;
import com.kakarote.examine.entity.BO.ExaminePageBO;
import com.kakarote.examine.entity.VO.ExamineAllVo;
import com.kakarote.examine.entity.VO.SuperExamineRecordVO;
import com.kakarote.examine.service.IExamineRecordService;
import com.kakarote.examine.service.ISuperExamineToDoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author JiaS
 * @date 2020/12/24
 */
@RestController
@RequestMapping("/examineSuperExamine")
@Api(tags = "超级审批办理列表接口")
public class SuperExamineToDoController {
    @Autowired
    private ISuperExamineToDoService superExamineService;

    @Autowired
    private IExamineRecordService examineRecordService;

    @Autowired
    private ISuperExamineToDoService iSuperExamineToDoService;


    @PostMapping("/getExportField/{categoryId}")
    @ApiOperation("获取审批导出字段")
    public Result<List<Map<String, Object>>> getExportField(@PathVariable("categoryId") Long categoryId) {
        return Result.ok(superExamineService.getExportField(categoryId));
    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param:
     * @return: com.kakarote.core.common.Result<java.util.List < java.util.Map < java.lang.String, java.lang.Object>>>
     * @throws:
     * @author: zyh
     * @date: 2022/8/27 11:18
     */
    @ApiOperation("待办-待我审批")
    @PostMapping(value = "/todo/me")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectToDoMe(@RequestBody ExaminePageBO examinePageBO) {
        return Result.ok(superExamineService.selectToDoMe(examinePageBO));
    }


    @PostMapping("/exportExamineDoMeInfo")
    @ApiOperation("导出代办待我审批")
    public void exportExamineInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineDoMeInfo(examinePageBO);

        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }

    @PostMapping("/exportExamineCopyMeInfo")
    @ApiOperation("导出代办抄送给我")
    public void exportExamineCopyMeInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineCopyMeInfo(examinePageBO);

        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param:
     * @return: com.kakarote.core.common.Result<java.util.List < java.util.Map < java.lang.String, java.lang.Object>>>
     * @throws:
     * @author: zyh
     * @date: 2022/8/27 11:19s
     */
    @ApiOperation("待办-抄送给我")
    @PostMapping(value = "/copy/me")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectCopyMe(@RequestBody ExaminePageBO
                                                                                              examinePageBO) {
        return Result.ok(superExamineService.selectCopyMe(examinePageBO));
    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examineBO
     * @return: com.kakarote.core.common.Result
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("待办-通过")
    @PostMapping(value = "/examine/pass")
    public Result passExamine(@RequestBody ExamineBO examineBO) {
        examineRecordService.auditExamine(examineBO);
        return Result.ok();
    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examineBO
     * @return: com.kakarote.core.common.Result
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("待办-拒绝")
    @PostMapping(value = "/examine/reject")
    public Result rejectExamine(@RequestBody ExamineBO examineBO) {
        examineRecordService.auditExamine(examineBO);
        return Result.ok();
    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examineBO
     * @return: com.kakarote.core.common.Result
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("待办-终止")
    @PostMapping(value = "/examine/end")
    public Result endExamine(@RequestBody ExamineBO examineBO) {
        examineRecordService.auditExamine(examineBO);
        return Result.ok();
    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examinePageBO
     * @return: com.kakarote.core.common.Result<com.kakarote.core.entity.BasePage < com.kakarote.core.feign.oa.entity.ExamineVO>>
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("归档-我申请的")
    @PostMapping(value = "/end/me")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectEndMe(@RequestBody ExaminePageBO examinePageBO) {
        BasePage<ExamineVO> basePage = superExamineService.selectEndMe(examinePageBO);
        return Result.ok(basePage);
    }


    @PostMapping("/exportExamineEenMeInfo")
    @ApiOperation("导出归档我申请的")
    public void exportExamineEenMeInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineEenMeInfo(examinePageBO);


        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examinePageBO
     * @return: com.kakarote.core.common.Result<com.kakarote.core.entity.BasePage < com.kakarote.core.feign.oa.entity.ExamineVO>>
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("归档-经我审批")
    @PostMapping(value = "/end/audit")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectEndAudit(@RequestBody ExaminePageBO
                                                                                                examinePageBO) {
        return Result.ok(superExamineService.selectEndAudit(examinePageBO));
    }

    @PostMapping("/exportExamineEenAuditInfo")
    @ApiOperation("导出归档经我审批")
    public void exportExamineEenAuditInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineEenAuditInfo(examinePageBO);

        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param:
     * @return: com.kakarote.core.common.Result<java.util.List < java.util.Map < java.lang.String, java.lang.Object>>>
     * @throws:
     * @author: zyh
     * @date: 2022/8/27 11:19s
     */
    @ApiOperation("归档-我关注的")
    @PostMapping(value = "/end/follow")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectEndFollow(@RequestBody ExaminePageBO
                                                                                                 examinePageBO) {
        return Result.ok(superExamineService.selectEndFollow(examinePageBO));
    }

    @PostMapping("/exportExamineEenFollowInfo")
    @ApiOperation("导出归档我的关注")
    public void exportExamineEenFollowInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineEenFollowInfo(examinePageBO);

        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param:
     * @return: com.kakarote.core.common.Result<java.util.List < java.util.Map < java.lang.String, java.lang.Object>>>
     * @throws:
     * @author: zyh
     * @date: 2022/8/27 11:19s
     */
    @ApiOperation("归档-作废的")
    @PostMapping(value = "/end/tovoid")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectEndToVoid(@RequestBody ExaminePageBO
                                                                                                 examinePageBO) {
        return Result.ok(superExamineService.selectEndToVoid(examinePageBO));
    }

    @PostMapping("/exportExamineEenTovoIdInfo")
    @ApiOperation("导出归档作废的")
    public void exportExamineEenTovoIdInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineEenTovoIdInfo(examinePageBO);

        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examinePageBO
     * @return: com.kakarote.core.common.Result<com.kakarote.core.entity.BasePage < com.kakarote.core.feign.oa.entity.ExamineVO>>
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("归档-抄送给我的")
    @PostMapping(value = "/end/copy")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectEndCopy(@RequestBody ExaminePageBO
                                                                                               examinePageBO) {
        return Result.ok(superExamineService.selectEndCopy(examinePageBO));
    }

    @PostMapping("/exportExamineEenCopyInfo")
    @ApiOperation("导出归档抄送我的")
    public void exportExamineEenCopyInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineEenCopyInfo(examinePageBO);

        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examinePageBO
     * @return: com.kakarote.core.common.Result<com.kakarote.core.entity.BasePage < com.kakarote.core.feign.oa.entity.ExamineVO>>
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("跟踪-我申请的")
    @PostMapping(value = "/track/me")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectTrackMe(@RequestBody ExaminePageBO
                                                                                               examinePageBO) {
        return Result.ok(superExamineService.selectTrackMe(examinePageBO));
    }


    @PostMapping("/exportExamineTrackMeInfo")
    @ApiOperation("导出跟踪我的申请")
    public void exportExamineTrackMeInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineTrackMeInfo(examinePageBO);


        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examinePageBO
     * @return: com.kakarote.core.common.Result<com.kakarote.core.entity.BasePage < com.kakarote.core.feign.oa.entity.ExamineVO>>
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("跟踪-经我审批的")
    @PostMapping(value = "/track/do")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectTrackDo(@RequestBody ExaminePageBO examinePageBO) {
        return Result.ok(superExamineService.selectTrackDo(examinePageBO));
    }

    @PostMapping("/exportExamineTrackDoInfo")
    @ApiOperation("导出跟踪经我审批")
    public void exportExamineTrackDoInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineTrackDoInfo(examinePageBO);


        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     * @param: examinePageBO
     * @return: com.kakarote.core.common.Result<com.kakarote.core.entity.BasePage < com.kakarote.core.feign.oa.entity.ExamineVO>>
     * @throws:
     * @author: zyh
     * @date: 2022/9/1 15:28
     */
    @ApiOperation("跟踪-抄送给我的")
    @PostMapping(value = "/track/copy")
    public Result<BasePage<com.kakarote.core.feign.oa.entity.ExamineVO>> selectTrackCopy(@RequestBody ExaminePageBO
                                                                                                 examinePageBO) {
        return Result.ok(superExamineService.selectTrackCopy(examinePageBO));
    }


    @PostMapping("/exportExamineTrackCopyInfo")
    @ApiOperation("导出跟踪抄送我的")
    public void exportExamineTrackCopyInfo(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {

        List<Map<String, Object>> mapList =
                superExamineService.exportExamineTrackCopyInfo(examinePageBO);


        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);

    }


    @PostMapping("/examine/record/list")
    @ApiOperation("获取审批详情")
    public Result<SuperExamineRecordVO> queryExamineRecordList(@RequestParam("recordId") Long
                                                                       recordId, @RequestParam(value = "ownerUserId", required = false) Long ownerUserId) {
        SuperExamineRecordVO recordVO = superExamineService.queryExamineRecordList(recordId, ownerUserId, null, 1);
        //设置已读
        iSuperExamineToDoService.setRecordLogRead(recordId, UserUtil.getUserId(), null, 1);
        return Result.ok(recordVO);
    }


    @PostMapping("/examine/queryAll")
    @ApiOperation("查询所有审批")
    public Result<BasePage<ExamineAllVo>> queryAllExamine(@RequestBody ExaminePageBO examinePageBO) {
        return Result.ok(superExamineService.queryAllExamine(examinePageBO));
    }

    @PostMapping("/exportAllExamine")
    @ApiOperation("导出跟踪抄送我的")
    public void exportAllExamine(@RequestBody ExaminePageBO examinePageBO, HttpServletResponse response) {
        List<Map<String, Object>> mapList =
                superExamineService.exportAllExamine(examinePageBO);
        ExcelParseUtil.exportApprovalExcel(mapList, "审批数据导出", examinePageBO.getFieldList(), response);
    }
}
